home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
32-bit_x86
/
Francais
/
cpsimage.cab
/
data
/
docio
/
fileio.elf
< prev
next >
Wrap
Text File
|
2009-03-16
|
2KB
|
75 lines
/*
** $Id: fileio.elf,v 1.4 2008/02/13 16:01:13 campanel Exp $
**
** Class for Text File IO
**
*******************************************************************************/
#load "sys/stdlib.elf";
/******************************************************************************/
/* @FILEIO */
/* @New This class is used for Input / Output with text files ??? what's unique about this?
*/
/* @initialize Causes the controller environment to be initialized. */
/******************************************************************************/
CLASS FILEIO {
METHOD New () { }
METHOD initialize (STRING filename, STRING iomode)
{
if (this.isInitialized == FALSE) {
this.filename = filename;
if (iomode.strcasecmp(str:"r") == TRUE)
{
this.isReader = TRUE;
this.fileContent = ReadObject(filename:filename, override: TRUE);
}
else if (iomode.strcasecmp(str:"w") == TRUE)
{
FILE file = new(FILE, path:filename);
if (file.exists() == TRUE)
file.deleteFile();
this.isReader = FALSE;
}
else if (iomode.strcasecmp(str:"a") == TRUE)
{
this.isReader = FALSE;
}
this.isInitialized = TRUE;
}
}
METHOD getLine() RETURNS (STRING line)
{
if (this.isReader == TRUE)
line = this.fileContent.getLine();
}
METHOD putline(STRING line)
{
if (this.isReader == FALSE)
{
INTEGER ind = line.length()-1;
STRING lastChar = line.index( val:ind );
line.Write (filename: this.filename, value: TRUE, mode: "a");
if (lastChar.strcasecmp(str: this.lnfeed) == FALSE)
this.lnfeed.Write (filename: this.filename, value: TRUE, mode: "a");
}
}
METHOD rewind()
{
if (this.isReader == TRUE)
this.fileContent.resetToken();
}
/* Internal Data Members */
STRING filename;
BOOLEAN isInitialized = FALSE;
BOOLEAN isReader = FALSE;
STRING fileContent;
STRING lnfeed = "\n";
}